<?php

namespace App\VO\UserConvertibleCard;

// use App\Entities\ConvertibleCardModel;
use App\BO\ConvertibleCard\Constant as ConvertibleCardConstant;
use App\BO\ConvertibleCard\Helper as ConvertibleCardHelper;
use App\Entities\ConvertibleCardEntity;
use App\Entities\UserConvertibleCardEntity;
use App\VO\Interfaces\IVOListItem;

class VOListItem implements IVOListItem
{
    use CommonTrait;

    public $cardId = 0;
    public $userCardId = 0;
    public $title = '';
    // public $price = 0;//分
    public $bannerImage = '';
    public $cardCode = '';
    public $expireDate = '';
    public $cardRemain = 0;
    public $phonenumber = '';
    public $cardRemainStr = '';

    public function __construct(UserConvertibleCardEntity $userCardEntity)
    {
        $cardId = $userCardEntity->getConvertibleCardId();
        $cardEntity = ConvertibleCardEntity::find($cardId);
        if ($cardEntity) {
            $this->assign($cardEntity);
            $this->cardId = $cardId;
            $this->cardRemain = ConvertibleCardHelper::userCardRemain($userCardEntity);
            $this->cardRemainStr = $this->cardRemainStr($this->cardRemain);
        }
        $this->userCardId = $userCardEntity->getId();
        $this->phonenumber = ConvertibleCardConstant::CUSTOMERSERVICE_PHONENUMBER;
        $this->cardCode = $userCardEntity->getCode();
        $this->expireDate = $userCardEntity->getExpireDate();
    }

    private function cardRemainStr(int $cardRemain)
    {
        $str = '剩余次数：';
        if ($cardRemain > 0) {
            $str .= $cardRemain . '次';
        } else {
            $str .= '已用完';
        }
        return $str;
    }
}
